<?php namespace App\Api\Http\Middleware;

use App\Exceptions\User\UserException;
use Closure;

class PublisherAuthenticate
{
    /**
     * Handle an incoming request.
     *
     * @param  \Illuminate\Http\Request $request
     * @param  \Closure                 $next
     *
     * @return mixed
     */
    public function handle($request, Closure $next)
    {
        $user = access()->user();
        if ($user && $user->isPublisher()) {
            return $next($request);
        }

        throw new UserException(UserException::NOT_PUBLISHER);
    }
}
